# -*-coding: utf-8 -*-
#Boa:Frame:Frame1

import sys
import os
sys.path.append("trunk")
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import wx
from widget import ToasterBox as TB
import wx.lib.hyperlink as hyperlink
from wx.lib.ticker import Ticker
from widget.wgtEventID import *
from widget.wgtTimer import TimerWindow
from widget.wgtMenu import *
from widget.wgtList import ListDemo

[wxID_FRAME1, wxID_FRAME1STATUSBAR1, 
] = [wx.NewId() for _init_ctrls in range(2)]

[wxID_FRAME1MENU1ITEMS0, wxID_FRAME1MENU1ITEMS1, 
] = [wx.NewId() for _init_coll_menu1_Items in range(2)]

[wxID_FRAME1MENUFILEITEMS0] = [wx.NewId() for _init_coll_menuFile_Items in range(1)]

class Frame1(wx.Frame):
    def _init_coll_menuFile_Items(self, parent):
        # generated method, don't edit

        parent.Append(help='', id=wxID_FRAME1MENUFILEITEMS0,
              kind=wx.ITEM_NORMAL, text='New')
        self.Bind(wx.EVT_MENU, self.OnMenuFileItems0Menu,
              id=wxID_FRAME1MENUFILEITEMS0)

    def _init_coll_statusBar1_Fields(self, parent):
        # generated method, don't edit
        parent.SetFieldsCount(1)

        parent.SetStatusText(number=0, text='status')

        parent.SetStatusWidths([-1])

    def _init_utils(self):
        # generated method, don't edit
        self.menuFile = wx.Menu(title=_('File'))

        self.menuHelp = wx.Menu(title=_('Help'))

        self._init_coll_menuFile_Items(self.menuFile)

    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(472, 247), size=wx.Size(400, 400),
              style=wx.DEFAULT_FRAME_STYLE, title='NewFrame')
        self._init_utils()
        self.SetClientSize(wx.Size(392, 366))
        self.SetStatusBarPane(2)
        self.SetToolTipString('Frame1')
        self.SetBackgroundColour(wx.Colour(51, 204, 189))
        self.SetThemeEnabled(True)
        self.Bind(wx.EVT_HELP, self.OnFrame1Help, id=wxID_FRAME1)
        self.Bind(wx.EVT_CLOSE, self.OnFrame1Close)

        self.statusBar1 = wx.StatusBar(id=wxID_FRAME1STATUSBAR1,
              name='statusBar1', parent=self, style=0)
        self._init_coll_statusBar1_Fields(self.statusBar1)
        self.SetStatusBar(self.statusBar1)

    def __init__(self, parent):
        self._init_ctrls(parent)

        self.tbicon = wx.TaskBarIcon()
        icon = wx.Icon('pizza.ico', wx.BITMAP_TYPE_ICO)
        self.tbicon.SetIcon(icon, '')
        

        wx.EVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarRightClick)
        wx.EVT_TASKBAR_LEFT_UP(self.tbicon, self.OnTaskBarRightClick)
        

#        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        

        self.SetMenuBar(MenuBarDemo())
        self.Bind(wx.EVT_MENU, self.onExit, id=ID_EXIT)
        self.Bind(wx.EVT_MENU, self.onSet, id=ID_SET)
        self.Bind(wx.EVT_MENU, self.onAbout, id=ID_ABOUT)
        self.Bind(wx.EVT_MENU, self.onRunServer, id=ID_RUNSERVER)
        
        panel = wx.Panel(self, -1)
        self.listBox = ListDemo(panel)
#        sizerV = wx.BoxSizer(wx.VERTICAL)
#        sizerV.Add(self.listBox, 1, wx.GROW)
        self.box = wx.BoxSizer(wx.VERTICAL)
        self.subbox = wx.BoxSizer(wx.HORIZONTAL)
        self.box.AddSizer(self.subbox)
        self.box.Add(self.listBox, 1, wx.GROW, 1)
        panel.SetSizer(self.box)
        panel.SetAutoLayout(True)
        
#        horSz = wx.BoxSizer(wx.HORIZONTAL)
#        runButton = wx.Button(panel, -1, "run TBox")
#        mainSz.Add((0, 3))
#        mainSz.Add(horSz, 1, wx.EXPAND | wx.BOTTOM, 7)
#        horSz.Add(runButton,1,0,1)
#        runButton.Bind(wx.EVT_BUTTON, self.run)
        

        self.SetSize((400, 400))
        self.Center()
        TimerWindow(self)

    def run(self):
        tbstyle = TB.TB_COMPLEX
        windowstyle = TB.TB_CAPTION
        closingstyle = TB.TB_ONCLICK
        tb = TB.ToasterBox(self, tbstyle=tbstyle, windowstyle=windowstyle, closingstyle=closingstyle)
        tb.SetTitle("hello title")
        tb.SetPopupSize((200, 150))
        tb.SetPopupPosition((824, 586))
        tb.SetPopupPauseTime(30000)
        tb.SetPopupScrollSpeed(8)
        tbpanel = tb.GetToasterBoxWindow()
        panel = wx.Panel(tbpanel, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)
        horsizer1 = wx.BoxSizer(wx.HORIZONTAL)
        # 设置位图
        myimage = wx.Bitmap("andrea.jpeg", wx.BITMAP_TYPE_JPEG)#
        stbmp = wx.StaticBitmap(panel, -1, myimage)
        horsizer1.Add(stbmp, 0)
        # 设置文字
        strs = "This Is Another Example Of ToasterBox, A Complex One. This Kind Of"
        strs = strs + " ToasterBox Can Be Created Using The Style TB_COMPLEX."
        sttext = wx.StaticText(panel, -1, strs)
        sttext.SetFont(wx.Font(7, wx.SWISS, wx.NORMAL, wx.NORMAL, False, "Verdana"))
        horsizer1.Add(sttext, 1, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
        # 设置链接
        hl = hyperlink.HyperLinkCtrl(panel, -1, "My Home Page",
                                     URL="http://xoomer.virgilio.it/infinity77/")
        
        sizer.Add((0,5))        
        sizer.Add(horsizer1, 0, wx.EXPAND) # sizer添加horizer1
        
        horsizer2 = wx.BoxSizer(wx.HORIZONTAL)
        horsizer2.Add((5, 0))
        horsizer2.Add(hl, 0, wx.EXPAND | wx.TOP, 10)
        sizer.Add(horsizer2, 0, wx.EXPAND) # sizer添加horizer2

        tk = Ticker(panel)
        tk.SetText("Hello From wxPython!")
        
        horsizer3 = wx.BoxSizer(wx.HORIZONTAL)
        horsizer3.Add((5, 0))
        horsizer3.Add(tk, 1, wx.EXPAND | wx.TOP, 10)
        horsizer3.Add((5,0))
        sizer.Add(horsizer3, 0, wx.EXPAND) # sizer添加horizer3
        
        sizer.Layout()
        panel.SetSizer(sizer)
        
        tb.AddPanel(panel)
        tb.Play()
    
    # 重写窗体关闭事件
#    def OnCloseWindow(self, evt):
#        self.Hide()
    
    # 右键单击任务栏处理方法
    def OnTaskBarRightClick(self, evt):
        print 'OnContextMenu'
        self.PopupMenu(PopupMenuDemo())
    
    def onAbout(self, evt):
        dlg = wx.MessageDialog(self, u'''

    def OnFrame1Help(self, event):
        event.Skip()

    def OnFrame1Close(self, event):
        event.Skip()

    def OnMenuFileItems0Menu(self, event):
        event.Skip()
技术支持:
    开发语言： Python
    Web框架：  Django 1.0
    类库：     wxPython, pyTTS
    第三方库： ToasterBox
    数据库：   Sqlite3

开发目标： 实现对事件的文字提示和语音提醒

运行环境： Windows

                           作者:张鹏''', u'关于', wx.OK)
        dlg.ShowModal()
        dlg.Destroy()
        
        
    def onSet(self, evt):
        self.Show()
    
    def onExit(self, evt):
        self.Close(0)
    
    def onRunServer(self, evt):
        print 'onRunServer'
    
    def OnFrame1Help(self, event):
        event.Skip()
    
    def OnFrame1Close(self, event):
        event.Skip()
    

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Frame1(None)
#    frame.Show()
    app.MainLoop()
